﻿using SUNRPA.CONTROLS.IMPL.domain.attrubutes;
using SUNRPA.CONTROLS.IMPL.domain.flowRunningVar;
using SUNRPA.CONTROLS.IMPL.util;
using System.Collections.Concurrent;
using System.IO;

namespace SUNRPA.CONTROLS.IMPL.domain.flowItemParam {
    [Serializable]
    [VarFieldName("FileSavePathOutVar")]
    public class DownLoadFileNParam : BaseParam {
        private string webObj = "{webPage}";
        private Element webEle;
        //等待下载对话框超时时间
        private string waitDialogTime = "20";
        //1点击按钮下载，2指定下载链接
        private int downloadMethod = 0;
        private string downloadAddr;
        //保存文件夹路径
        private string savePath =  Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)+Path.DirectorySeparatorChar+"Downloads";
        private bool renameDownloadFile = false;
        private bool waitingDownloadFinish = true;
        //重命名名称
        private string saveFileName;
        private string expireTime = "300";
        //下载地址输出变量
        private string fileSavePathOutVar = "fileSavePath";

        public string FileSavePathOutVar {
            get => fileSavePathOutVar; 
            set { 
                fileSavePathOutVar = value;
                NotifyPropertyChanged("FileSavePathOutVar");
            }  
        }

        public string ExpireTime {
            get => expireTime; 
            set { 
                expireTime = value;
                NotifyPropertyChanged("ExpireTime");
            }  
        }

        public bool WaitingDownloadFinish {
            get => waitingDownloadFinish; 
            set { 
                waitingDownloadFinish = value;
                NotifyPropertyChanged("WaitingDownloadFinish");
            }  
        }

        public string SaveFileName {
            get => saveFileName; 
            set { 
                saveFileName = value;
                NotifyPropertyChanged("SaveFileName");
            }  
        }

        public bool RenameDownloadFile {
            get => renameDownloadFile; 
            set { 
                renameDownloadFile = value;
                NotifyPropertyChanged("RenameDownloadFile");
            }  
        }

        public string SavePath {
            get => savePath; 
            set { 
                savePath = value;
                NotifyPropertyChanged("SavePath");
            }  
        }

        public string DownloadAddr {
            get => downloadAddr; 
            set { 
                downloadAddr = value;
                NotifyPropertyChanged("DownloadAddr");
            }  
        }
        
        public int DownloadMethod {
            get => downloadMethod; 
            set { 
                downloadMethod = value;
                NotifyPropertyChanged("DownloadMethod");
            }  
        }

        public string GetTranslateDownloadMethod() {
            switch(this.downloadMethod) {
                case 0:
                    return "点击下载按钮";
                case 1:
                    return $"下载链接{this.downloadAddr}";
                default : return "左键";
            }
        }

        public string GetTranslateWaitingDownloadFinish() {
            if(true) { 
                return $"最多等待{this.expireTime}后，";
            } else { 
                return "";
            }
        }

        public string GetTranslateRenameDownloadFile() {
            if(true) { 
                return $"重命名为{this.saveFileName}";
            } else { 
                return "";
            }
        }

        public string WebObj {
            get => webObj;
            set {
                webObj = value;
                NotifyPropertyChanged("WebObj");
            }
        }
        public Element WebEle {
            get => webEle;
            set {
                webEle = value;
                NotifyPropertyChanged("WebEle");
            }
        }

        public string WaitDialogTime {
            get => waitDialogTime; 
            set { 
                waitDialogTime = value;
                NotifyPropertyChanged("WaitDialogTime");
            }  
        }
        public override void SetLatestVarName(ConcurrentDictionary<string, ConcurrentDictionary<string, RPAVariableDefineWrapper>> globleData) {
            this.fileSavePathOutVar = this.GetLatestName(this.fileSavePathOutVar, globleData);
        }
    }
}
